<?php

use yii\db\Migration;

class m170506_072503_alter_customer_coupons extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%customer_coupons}}', 'coupons_code_id', $this->integer() . ' default 0 comment \'券码id\'');
            $this->addColumn('{{%customer_coupons}}', 'invalid_time', $this->integer() . ' default 0 comment \'失效时间\'');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%customer_coupons}}', 'coupons_code_id');
            $this->dropColumn('{{%customer_coupons}}', 'invalid_time');
        }
    }
}
